import java.util.*;

public class 第二题 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = sc.nextLine().trim().split(",");
        int[] nums = new int[s.length];
        Queue<Integer> queue = new LinkedList<>();
        for (int i = 0; i < s.length; i++) {
            queue.add(i);
            nums[i] = Integer.parseInt(s[i]);
        }
        String[] s2 = sc.nextLine().trim().split(",");
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < s2.length; i++) {
            String[] temp = s2[i].trim().split("->");
            map.put(Integer.parseInt(temp[0]), Integer.parseInt(temp[1]));
        }
        int time = 0;
        Map<Integer, Integer> res = new HashMap<>();
        while (!queue.isEmpty()) {
            int first = queue.peek();
            if (queue.contains(map.get(first))) {
                queue.add(queue.poll());
            } else {
                time += nums[first];
                res.put(first, time);
                queue.poll();
            }
        }
        StringBuilder ans = new StringBuilder(String.valueOf(res.get(0)));


        for (int i = 1; i < nums.length; i++) {
            ans.append(",");
            ans.append(res.get(i));

        }

        System.out.println(ans.toString());
    }


}

